package org.NooLab.randomgraph.properties;

import java.io.Serializable;
import java.util.ArrayList;

import org.NooLab.randomgraph.RandomGraphFactory;
import org.NooLab.randomgraph.app.RGraphStartup;
import org.NooLab.randomgraph.util.FileOrganizer;
import org.NooLab.structures.randomgraph.PersistenceSettingsIntf;
import org.NooLab.structures.randomgraph.RGraphPropertiesDefaultIntf;





public class RGraphProperties 
								implements 
											Serializable,
											RGraphPropertiesDefaultIntf,
											RGraphPropertiesIntf{

	
	RGraphPropertiesDefaults rgPropertiesDefaults;
	PersistenceSettings persistenceSettings ;
	
	protected String systemRootDir ="";

	// ..........................................
	private int lengthFingerprints = 10;
	private int lengthResultVector = 80;
	private int lengthNeighborhood = 5 ;

	// ..........................................
	private int leftEmphasis = 0 ;
	private boolean isPOSsensitive = false;
	
	// PluggedCapabilities pCap;
	private boolean isAvoidNILinContexts;
	
	ArrayList<Integer> variants = new ArrayList<Integer>();
	
	
	/** this requires a running ML-SOM. 
	 * This would be accessed through a dedicated class to query it.
	 * The query then runs through TCP.
	 * Note that there is only 1 single main entry SomStore. 
	 * The SomStore is itself responsible for processing the query if there is more than one
     */
	boolean createSentenceLevelContexts = true;
	
	/** pays only for large arrays of primitives (n>300) or
	 *  for large array of structured objects 
	 */
	private boolean isDatabaseProfileStoreAsObject = false ;
	private boolean isUseMemMappingForFingerPrints = true ; // except for large corpora! 
	private int memMappingThreshold = 500000;
	
	private String columnPrefix;
	private int levelOfWordNormalization;
	private int numberOfConsideredSynonyms;
	private String applicationContext = "";
	
	
	// ========================================================================
	public RGraphProperties(){
		
		FileOrganizer fileorg = new FileOrganizer ();
		rgPropertiesDefaults = new RGraphPropertiesDefaults(this);
		persistenceSettings = new PersistenceSettings(this,fileorg ) ;
	}
	// ========================================================================
	
	public void initializeDefaults() {
		
		persistenceSettings.setProjectName( RGraphStartup.getLastProjectName() );	
		rgPropertiesDefaults.prepareStartupTraceInfo();
	}
	
	public boolean initializationOK() {

		return false;
	}



	public void setInitializationOK(boolean flag) {

		
	}



	public void save() {

		
	}



	public RGraphPropertiesDefaults getRgPropertiesDefaults() {
		return rgPropertiesDefaults;
	}

	public PersistenceSettingsIntf getPersistenceSettings() {
		return (PersistenceSettingsIntf) persistenceSettings;
	}



	public String getSystemRootDir() {
		
		systemRootDir = persistenceSettings.getPathToSomFluidSystemRootDir();
		return systemRootDir;
	}



	public void setSystemRootDir(String rootDir) {
		this.systemRootDir = rootDir;
		persistenceSettings.systemRootDir = rootDir; 
	}

	public void setProjectName(String prjname) {
		persistenceSettings.setProjectName( prjname) ;
	}
	public String getProjectName() {
		String prjname = persistenceSettings.getProjectName() ;
		return prjname;
	}

	public void setProjectNameByInstance(int instanceType) {
		
		String prj="text";
		
		if ( instanceType==RandomGraphFactory._INSTANCE_TYPE_TEXT ){
			prj = "text";
		}
		if ( instanceType==RandomGraphFactory._INSTANCE_TYPE_IMAGE){
			prj = "image";
		}
		if ( instanceType==RandomGraphFactory._INSTANCE_TYPE_DATA){
			prj = "data";
		}
		if ( instanceType==RandomGraphFactory._INSTANCE_TYPE_DOUBLET){
			prj = "doublet";
		}

		persistenceSettings.setProjectName( prj );
	}

	public void setLengthItemFingerprints(int len) {
		
		if (len<5){
			len=5;
		}
		if (len>100){
			len=100;
		}
		lengthFingerprints = len;
	}

	public void setLengthResultVector(int len) {
		if (len<20){
			len=20;
		}
		if (len>200){
			len=200;
		}
		lengthResultVector = len;
	}

	public int getLengthFingerprints() {
		return lengthFingerprints;
	}

	public void setLengthFingerprints(int lengthFingerprints) {
		this.lengthFingerprints = lengthFingerprints;
	}

	public int getLengthResultVector() {
		return lengthResultVector;
	}

	public void setLengthNeighborhood(int nvalue) {
		lengthNeighborhood = nvalue;
		
	}

	public void setIsPOSsensitive(boolean flag) {
		isPOSsensitive = flag ;
		
	}

	public void setIsLeftEmphasis(int leValue) {
		leftEmphasis = leValue ;
	}

	public int getLeftEmphasis() {
		return leftEmphasis;
	}

	public void setLeftEmphasis(int leftEmphasis) {
		this.leftEmphasis = leftEmphasis;
	}

	public boolean isPOSsensitive() {
		return isPOSsensitive;
	}

	public void setPOSsensitive(boolean isPOSsensitive) {
		this.isPOSsensitive = isPOSsensitive;
	}

	public int getLengthNeighborhood() {
		return lengthNeighborhood;
	}

	public int getPoStagSensitiveAsymmetry() {
		
		return 0;
	}


	public boolean getAvoidNILinContexts() {
		
		return isAvoidNILinContexts;
	}


	public boolean isCreateSentenceLevelContexts() {
		return createSentenceLevelContexts;
	}

	public void setCreateSentenceLevelContexts(boolean createSentenceLevelContexts) {
		this.createSentenceLevelContexts = createSentenceLevelContexts;
	}

	public boolean isAvoidNILinContexts() {
		return isAvoidNILinContexts;
	}

	public void setAvoidNILinContexts(boolean isAvoidNILinContexts) {
		this.isAvoidNILinContexts = isAvoidNILinContexts;
	}

	public void setDatabaseProfileStoreAsObject(boolean flag) {
		isDatabaseProfileStoreAsObject = flag ;
	}

	public boolean isDatabaseProfileStoreAsObject() {

		return isDatabaseProfileStoreAsObject;
	}

	public boolean isUseMemMappingForFingerPrints() {
		return isUseMemMappingForFingerPrints;
	}

	public void setUseMemMappingForFingerPrints(boolean flag) {
		this.isUseMemMappingForFingerPrints = flag;
	}

	public int getMemMappingThreshold() {
		return memMappingThreshold;
	}

	public void setMemMappingThreshold(int memMappingThreshold) {
		this.memMappingThreshold = memMappingThreshold;
	}

	public void setColumnPrefix(String prefixstr) {
		
		columnPrefix = prefixstr;
	}

	public String getColumnPrefix() {
		return columnPrefix;
	}

	// ....................................................
	public boolean isVariantActive(int variantId){
		
		boolean rB=false;
		int p = variants.indexOf(variantId);
		if (p>=0){
			rB=true;
		}
		return rB;
	}
	
	public ArrayList<Integer>  getVariants(){
		return variants ;
	}
	
	public void addVariant(int variantId) {
		
		if (variants.indexOf(variantId)<0){
			variants.add(variantId);
		}
	}
	public void removeVariant(int variantId) {
		
		int p = variants.indexOf(variantId);
		if (p>=0){
			variants.remove(p);
		}
	}
	
	public void clearAllVariants() {
		variants.clear();
	}
	
	
	public void setLevelOfWordNormalization(int value) {
		
		levelOfWordNormalization = value;
	}

	public void setNumberOfConsideredSynonyms(int value) {

		numberOfConsideredSynonyms = value;
	}
	// ....................................................

	public int getLevelOfWordNormalization() {
		return levelOfWordNormalization;
	}

	public int getNumberOfConsideredSynonyms() {
		return numberOfConsideredSynonyms;
	}

	@Override
	public String getApplicationContext() {
		return applicationContext ;
	}

	@Override
	public void setApplicationContext(String appContext) {
		applicationContext = appContext;
		
	}
}
